/*
 * Copyright (c) 2018, ZeeSec Technologies. All rights reserved.
 * ZeeSec PROPRIETARY/CONFIDENTIAL.
 */

package springtest.springWebSocket;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.socket.config.annotation.EnableWebSocket;
import org.springframework.web.socket.config.annotation.WebSocketConfigurer;
import org.springframework.web.socket.config.annotation.WebSocketHandlerRegistry;
import org.springframework.web.socket.handler.TextWebSocketHandler;

/**
 * @author ZhiQiang Chen
 * @date 2018-12-03 11:07:04
 */
@Configuration
@EnableWebSocket
public class WebSocketConfig implements WebSocketConfigurer {

    @Override
    public void registerWebSocketHandlers(WebSocketHandlerRegistry registry) {
        registry.addHandler(getCustoMessageHandle(), "/webSocket").addInterceptors(new CustomWebSocketInterceptor());
        registry.addHandler(getCustoMessageHandle(), "/sockjs/webSocket")
                .addInterceptors(new CustomWebSocketInterceptor()).withSockJS();
    }

    @Bean
    public TextWebSocketHandler getCustoMessageHandle() {
        return new CustoMessageHandle();
    }

}
